package com.sadam.ui4.FragmentMessagePage;

import com.sadam.ui4.Data.Video;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class LikeMessage {
    private String username;       // 点赞者用户名
    private String timeAgo;        // 时间（如 "3分钟前"）
    private String avatarUrl;      // 点赞者头像
    private String coverUrl;       // 视频封面路径（用于生成缩略图）
    private String videoTitle;     // 视频标题
    private long likeTime;         // 点赞时间戳（用于计算 timeAgo）
    private Video video;           // 新增：持有 Video 对象

    // 构造函数：用于测试数据
    public LikeMessage(String username, String timeAgo, String avatarUrl, String coverUrl, String videoTitle) {
        this.username = username;
        this.timeAgo = timeAgo;
        this.avatarUrl = avatarUrl;
        this.coverUrl = coverUrl;
        this.videoTitle = videoTitle;
    }

    // 新增构造函数：用于从数据库构建（自动计算 timeAgo）
    public LikeMessage(String username, String avatarUrl, String videoTitle, String coverUrl, long likeTime, Video video) {
        this.username = username;
        this.avatarUrl = avatarUrl;
        this.videoTitle = videoTitle;
        this.coverUrl = coverUrl;
        this.likeTime = likeTime;
        this.video = video; // 保存 Video 对象
        this.timeAgo = calculateTimeAgo(likeTime);
    }

    // 计算时间差的方法
    private String calculateTimeAgo(long timestamp) {
        long now = System.currentTimeMillis();
        long diff = now - timestamp;

        long seconds = diff / 1000;
        long minutes = seconds / 60;
        long hours = minutes / 60;
        long days = hours / 24;

        if (minutes < 1) {
            return "刚刚";
        } else if (minutes < 60) {
            return minutes + "分钟前";
        } else if (hours < 24) {
            return hours + "小时前";
        } else if (days < 7) {
            return days + "天前";
        } else {
            return new SimpleDateFormat("M月d日", Locale.CHINA).format(new Date(timestamp));
        }
    }

    // Getter 方法
    public String getUsername() {
        return username;
    }

    public String getTimeAgo() {
        return timeAgo;
    }

    public String getAvatarUrl() {
        return avatarUrl;
    }

    public String getCoverUrl() {
        return coverUrl;
    }

    public String getVideoTitle() {
        return videoTitle;
    }

    public long getLikeTime() {
        return likeTime;
    }

    public Video getVideo() {
        return video;
    }
}